<?php 
if (! defined('BASEPATH')) {
	exit('Access Denied');
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>插件编辑</title>
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>/static/css/admin/base.css">
<link rel="stylesheet" href="<?php echo base_url();?>/static/js/editor/themes/default/default.css" />
<style>
img{
	cursor:pointer
}
</style>

<script src="<?php echo base_url();?>/static/js/jquery.js" language="javascript"></script>

<script src="<?php echo base_url();?>/static/js/validate/validator.js" language="javascript"></script>

<script type="text/javascript">


$(document).ready(function() {
//提交
$("#btnSave").click(function(){
    if($("#newform").Valid() == false || !$("#newform").Valid()) return false;
});


});
var i_num = <?php echo count($c_array) ;?> ;
var s_num = 0 ;
//添加

function add_controller(){
	var s = '<tr align="" bgcolor="#FAFAF1" height="32" id="myid_'+i_num+'">';
	s+='<td><span style="margin-left:40px"></span>控制器'+i_num+':&nbsp;控制器名称：<input type="text" name="c_name[]" style="width:140px; height:22px"> &nbsp;路径：<input type="text" name="c_path[]" style="width:200px; height:22px">&nbsp;&nbsp;是否是功能性:<select id="isfunction" name="isfunction[]"><option value="1">是</option><option value="0" selected="selected">否</option></select>如果<font color="red">否</font>将在左边菜单显示&nbsp;&nbsp;';
	var del_id = 'myid_'+i_num ;
	s+='<img src="<?php echo base_url();?>/static/image/admin/gtk-del.png" onclick="del_(\''+del_id+'\')" title="点击删除" alt="点击删除"> </td>';
	s+='</tr>';
	$("#myadd").append(s);
	i_num++ ;

}
function del_(id,type = '',pid = '' ){
	$("#"+id).remove();
	
	if(type == 'all'){
		$(".myclass_"+pid).remove();
		$("[id^='mychild_"+pid+"']").remove();
	}
}

//添加子类
function add_child_controller(id,reid=''){
	var myid = "mychild_"+id+"_"+s_num ;
	var child = "<tr bgcolor=\"#FAFAF1\" id=\"mychild_"+id+"_"+s_num+"\">";
	
	child+='<td>';
	child+='<hr style="border:solid 1px #CCCCCC;  height:1px"></hr>';
	child+='<span style="margin-left:10%"></span>';
	child+='名称:<input type="text" style="width:140px; height:22px" name="c_child_name[]">&nbsp;&nbsp;';
	child+='路径:<input id="" type="text" value="" name="c_child_path[]" style="width:200px; height:22px">';
	child+='<input id="" type="hidden" value='+reid+' name="reid[]" style="width:200px; height:22px">';
	child+='<img onclick="del_(\''+myid+'\')" src="<?php echo base_url() ;?>/static/image/admin/gtk-del.png" alt="请点击删除" title="请点击删除">';
	child+='</td>';
	child+='</tr>';
	$("#myid_"+id).after(child);
	s_num++;
}
</script>
</head>
<body leftmargin="8" topmargin="8">
<div class="nav_des">
<span class="des">插件管理>></span>
	
	<a href="<?php echo site_url("admin/plus_manager/index/pluginlist");?>" >插件管理</a>
	<a href="javascript:void(0)" class="nav_des_hover"> 插件编辑</a>
</div>

<!--  内容列表   -->


<form name="form2" method="post" name="" action="<?php echo site_url("admin/plus_manager/index/plugin_edit");?>" id="newform">
<input type="hidden" value="<?php echo $one['id'];?>" name="id">
<input type="hidden" value="plugin_edit_do" name="action">
<table width="98%" border="0" cellpadding="2" cellspacing="1" bgcolor="#D1DDAA" align="center" style="margin-top:8px">
<tr bgcolor="#E7E7E7" >
	<td height="24" colspan="" >&nbsp;插件编辑&nbsp;</td>
</tr>
<tr align="" bgcolor="#FAFAF1" height="30">
	<td >插件名称:<input type="text" name="plugin_name" class="form_input"  required="true" errmsg="请输入60个字符之内" tip="请输入60个字符之内" style="width:300px" value="<?php echo $one['plugin_name'];?>"> </td>
</tr>

<tr align="" bgcolor="#FAFAF1" height="22">
	<td >插件状态:
	<select name="status" style="width:300px">
		<option value="1" <?php if($one['status'] == '1'){echo "selected='selected'";}?>>开启</option>
		<option value="0"  <?php if($one['status'] == '0'){echo "selected='selected'";}?>>关闭</option>
		<option value="2" <?php if($one['status'] == '2'){echo "selected='selected'";}?>>删除</option>
	</select>
</td>
</tr>


<tbody id="myadd">
<?php 
	if($c_array){
		$kk_num = 0 ;
		foreach($c_array as $c_key=>$c_val){
			
?>
<tr id="myid_<?php echo $kk_num ;?>" height="32" bgcolor="#FAFAF1" align="" class="myclass_<?php echo $kk_num;?>">
<td>
<input type="hidden" name="ids[]" value="<?php echo $c_val['id'];?>">
<span style="margin-left:40px"></span>
控制器<?php echo $kk_num ;?>：控制器名称：
<input type="text" style="width:140px; height:22px" name="c_name[]" value="<?php echo isset($c_val['c_name'])?$c_val['c_name']:'' ;?>">
<img src="<?php echo base_url();?>/static/image/admin/add.png" width="16px" height="16px" onclick="add_child_controller(<?php echo $kk_num ;?>,<?php echo $c_val['id'];?>);" style="cursor:pointer">
<input type="text" style="width:200px; height:22px" name="c_path[]" value="<?php echo isset($c_val['url'])?$c_val['url']:'' ;?>">
&nbsp;&nbsp;是否是功能性:<select id="isfunction" name="isfunction[]"><option value="1" <?php if(isset($c_val['isfunction']) && $c_val['isfunction']==1){echo "selected='selected'";}?>>是</option><option value="0" <?php if(isset($c_val['isfunction']) && $c_val['isfunction']==0){echo "selected='selected'";}?>>否</option></select>如果<font color="red">否</font>将在左边菜单显示&nbsp;&nbsp;

<img onclick="del_('myid_<?php echo $kk_num ;?>','all',<?php echo $kk_num ;?>)" src="<?php echo base_url() ;?>/static/image/admin/gtk-del.png" alt="请点击删除" title="请点击删除">

</td>
</tr>
<?php 
	if(isset($c_val['son']) && !empty($c_val['son'])){
		
		foreach($c_val['son'] as $son_key=>$son_val){
?>
<tr bgcolor="#FAFAF1" id="mychild_exists_<?php echo $son_val['id'];?>" class="myclass_<?php echo $kk_num;?>">
	<td>
	<hr style="border:solid 1px #CCCCCC; height:1px">
	<span style="margin-left:10%"></span>
	名称:<input type="text" name="c_child_name[]" style="width:140px; height:22px" value="<?php echo isset($son_val['c_name'])?$son_val['c_name']:'' ;?>">
	 路径:
	<input id="" type="text" style="width:200px; height:22px" name="c_child_path[]" value="<?php echo isset($son_val['url'])?$son_val['url']:'' ;?>">
	<input id="" type="hidden" style="width:200px; height:22px" name="reid[]" value="<?php echo isset($c_val['id'])?$c_val['id']:'';?>">
	<img title="请点击删除" alt="请点击删除" src="<?php echo base_url() ;?>/static/image/admin/gtk-del.png" onclick="del_('mychild_exists_<?php echo $son_val['id'];?>')">
	<input name="sonid[]" value="<?php echo $son_val['id'];?>" type="hidden">
	</td>
</tr>
<?php 
		}
	}	
?>
<?php
		$kk_num++ ;
	 }
}
?>
</tbody>
<tr align="" bgcolor="#FAFAF1" height="32">
	<td >控制器方法:
		<img src="<?php echo base_url();?>/static/image/admin/add.png" width="16px" height="16px" onclick="add_controller();" style="cursor:pointer">&nbsp;&nbsp;添加主控制器
	</td>
</tr>
<tr bgcolor="#FAFAF1">
<td height="28" colspan="">
	&nbsp;

	<input type="submit" value="提&nbsp;&nbsp;交" class="coolbg" id='btnSave'>
</td>
</tr>

</table>

</form>

</body>
</html>